﻿//
// Copyright (c) 2024 BPer
//
#ifndef __BPerVideoDecoderHandle__
#define __BPerVideoDecoderHandle__

#include <bperutil/buffer/BPerVideoDecoderBuffer.h>
#include <bperutil/buffer/BPerVideoBuffer.h>
#include <bperutil/sys/BPerThread2.h>
#include <bperdecoder/BPerVideoDecoder.h>
#include <bperutil/BPerAvInfoType.h>
#include <vector>

using namespace std;
class BPerVideoDecoderHandle:public BPerThread,public BPerDecoderCallback
{
public:
	BPerVideoDecoderHandle(BPerContext *pcontext);
	~BPerVideoDecoderHandle(void);

private:
	int32_t isInit;

public:
	int32_t m_isStart;
	BPerVideoDecoder *getDecoder(int32_t puid);
	BPerVideoBuffer* getOutVideoBuffer();

	void parseVideoHeader(uint8_t *p,int32_t pind);
	void addVideoStream(uint8_t *ps,int32_t pind,int32_t pisAdd);

	void init();
	void stop();
	void setInVideoBuffer(BPerVideoDecoderBuffer *pbuf);
	void setOutVideoBuffer(BPerVideoBuffer* pbuf);

	void onAudioData(BPerFrame* pframe);
	void onVideoData(BPerFrame* pframe);




protected:
	void run();
	void stopLoop();
	void startLoop();


void saveFile(char *fileName, uint8_t *pBuffer, long BufferLen);

private:
	BPerVideoDecoderBuffer *m_in_videoBuffer;
	BPerVideoBuffer *m_out_videoBuffer;
	BPerVideoDecoder *m_decs;

	int32_t m_isConvert;
	BPerContext *m_context;

	void decode(int32_t isIframe,uint8_t*src,int32_t  p_buflen,uint8_t *dest,int32_t *p_destLen);


};
#endif
